package cn.sc.allinpay.allfavour.business.cashier;

import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;

import com.google.zxing.integration.android.IntentIntegrator;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.model.KeyValueInfo;
import cn.sc.allinpay.allfavour.business.member.MemberActivity;

/**
 * 收银
 */
public class CashierActivity extends BaseActivity<CashierContract.View, CashierContract.Presenter> implements CashierContract.View {

    @BindView(R.id.etGuideID)
    AppCompatEditText etGuideID;//导购ID
    @BindView(R.id.etGuideName)
    AppCompatEditText etGuideName;//导购姓名
    @BindView(R.id.tvTransAmt)
    AppCompatTextView tvTransAmt;//消费金额

    @BindView(R.id.llMember)
    RelativeLayout llMember;//会员视图
    @BindView(R.id.btnMember)
    AppCompatButton btnMember;//会员按钮
    @BindView(R.id.tvMemberLevel)
    AppCompatTextView tvMemberLevel;//等级
    @BindView(R.id.tvMemberName)
    AppCompatTextView tvMemberName;//会员名称
    @BindView(R.id.tvMemberNo)
    AppCompatTextView tvMemberNo;//会员号

    @BindView(R.id.tvDiscountExist)
    AppCompatTextView tvDiscountExist;//会员优惠是否存在
    @BindView(R.id.tvDiscountAmt)
    AppCompatTextView tvDiscountAmt;//会员优惠
    @BindView(R.id.llDiscount)
    RelativeLayout llDiscount;//会员视图
    @BindView(R.id.tvCouponsNumber)
    AppCompatTextView tvCouponsNumber;//卡券数量
    @BindView(R.id.tvCouponsAmt)
    AppCompatTextView tvCouponsAmt;//卡券优惠金额
    @BindView(R.id.tvEWalletBal)
    AppCompatTextView tvEWalletBal;//电子钱包余额
    @BindView(R.id.tvEWalletAmt)
    AppCompatTextView tvEWalletAmt;//电子钱包使用金额

    @BindView(R.id.tvPaidAmt)
    AppCompatTextView tvPaidAmt;//待支付金额

    @BindView(R.id.spOilType)
    AppCompatSpinner spOilType;




    @Override
    protected int layoutId() {
        return R.layout.activity_cashier;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("收银台");
    }

    @Override
    protected CashierContract.Presenter bindPresenter() {
        return new CashierPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {

    }

    @OnClick({R.id.btnMember, R.id.btnPay, R.id.llDiscount, R.id.llCoupons, R.id.llEWallet})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnMember:
                spOilType.setEnabled(false);
                new IntentIntegrator(this).setOrientationLocked(false).
                        setCaptureActivity(MemberActivity.class).initiateScan();
                break;
            case R.id.btnPay:
                presenter.startPay();//去支付
                break;
            case R.id.llCoupons://卡券核销
                presenter.startCouponsActivity();
                break;

            case R.id.llEWallet:
                presenter.startEWalletActivity();
                break;
        }
    }

    @Override
    public String getGuideID() {
        return etGuideID.getText().toString().trim();
    }

    @Override
    public String getGuideName() {
        return etGuideName.getText().toString().trim();
    }

    @Override
    public String getOilType() {
        return  ((KeyValueInfo) (spOilType.getSelectedItem())).getValue();
    }

    @Override
    public String getOilName() {
        return  ((KeyValueInfo) (spOilType.getSelectedItem())).getKey();
    }

    @Override
    public void showTransAmt(String amt) {
        tvTransAmt.setText(amt);
    }

    @Override
    public void showMemberLevel(String data) {
        tvMemberLevel.setText(data);
    }

    @Override
    public void showMemberName(String data) {
        tvMemberName.setText(data);
    }

    @Override
    public void showMemberNo(String data) {
        tvMemberNo.setText(data);
    }

    @Override
    public void showDiscountExist(String data) {
        tvDiscountExist.setText(data);
    }

    @Override
    public void showDiscountAmt(String data) {
        tvDiscountAmt.setText(data);
    }

    @Override
    public void showCouponsNumber(String data) {
        tvCouponsNumber.setText(data);
    }

    @Override
    public void showCouponsAmt(String data) {
        tvCouponsAmt.setText(data);
    }

    @Override
    public void showEWalletBal(String data) {
        tvEWalletBal.setText(data);
    }

    @Override
    public void showEWalletAmt(String data) {
        tvEWalletAmt.setText(data);
    }

    @Override
    public void showPaidAmt(String amt) {
        tvPaidAmt.setText(amt);
    }

    @Override
    public void showOilType() {
        List<KeyValueInfo> dataList = new ArrayList<KeyValueInfo>();
        KeyValueInfo info = new KeyValueInfo("92#","01");
        dataList.add(info);
        info = new KeyValueInfo("95#","02");
        dataList.add(info);
        info = new KeyValueInfo("98#","03");
        dataList.add(info);
         info = new KeyValueInfo("0#","04");
        dataList.add(info);
        info = new KeyValueInfo("LNG","06");
        dataList.add(info);
        info = new KeyValueInfo("CNG","05");
        dataList.add(info);
        info = new KeyValueInfo("非油品","07");
        dataList.add(info);
        info = new KeyValueInfo("其它","08");
        dataList.add(info);
        ArrayAdapter<KeyValueInfo> arrayAdapter = new ArrayAdapter<KeyValueInfo>(this, android.R.layout.simple_spinner_dropdown_item, dataList);

        spOilType.setAdapter(arrayAdapter);

        spOilType.setOnItemSelectedListener(new AppCompatSpinner.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    @Override
    public void showMemberVisible(int visible) {
        llMember.setVisibility(visible);
        btnMember.setVisibility(View.VISIBLE == visible ? View.GONE : View.VISIBLE);
    }
}
